package org.witsoft.dtx.example.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.witsoft.dtx.core.TransactionBranchHandler;
import org.witsoft.dtx.example.domain.WalletEvent;
import org.witsoft.dtx.example.domain.WalletLog;
import org.witsoft.dtx.example.service.TransferService;
import org.witsoft.dtx.example.service.WalletService;

import java.math.BigDecimal;

/**
 * @author XiaoQing Lin
 * @date 2020-09-21 16:41
 */
@Component
public class WalletTransferOutHandler implements TransactionBranchHandler {

    @Autowired
    private WalletService walletService;

    public void confirm(String globalId, String branchId, String argument) {

    }

    public void cancel(String globalId, String branchId, String argument) {
        String[] args = argument.split("[|]");
        int userId = Integer.parseInt( args[0]);
        String orderId = args[1];
        walletService.revert(userId, WalletEvent.TRANSFER_OUT, orderId);
        System.out.println(1/0);
    }
}
